//
//  SINAStudentSettingViewController.m
//  sinashebao
//
//  Created by  androidlongs on 2017/12/21.
//  Copyright © 2017年  androidlongs. All rights reserved.
//

#import "SINAStudentSettingViewController.h"
#import "SINALoginViewController.h"
#import "SINANavLoginViewController.h"
#import "SINAStudentCountSafeViewController.h"
#import "SINAAboutMeViewController.h"
#import "SINAStudentSelectIdentViewController.h"
#import "SINAControllerUtils.h"
#import "SINAHelpFeedbackViewController.h"
#import "JPUSHService.h"

@interface SINAStudentSettingViewController ()
@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;

@end

@implementation SINAStudentSettingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self configNavigationItem];
    
    self.scrollView.contentSize = CGSizeMake(mainW, mainH+1);
    [self.scrollView setBackgroundColor:[UIColor colorWithHexString:@"#eeeeee"]];
    
    
    //账号安全
    UIView *typeView  = [[UIView alloc]initWithFrame:CGRectMake(0, 15, mainW, 47)];
    [typeView setBackgroundColor:[UIColor whiteColor]];
    UILabel *typeLabel = [[UILabel alloc]initWithFrame:CGRectMake(15, 0, mainW-24, 45)];
    typeLabel.text=@"账号安全";
    [typeLabel setTextColor:[UIColor colorWithHexString:@"#2e2e2e"]];
    [typeView addSubview:typeLabel];
   
    [[SINAUiviewClickLiserner alloc]viewClickFunction:typeView andWithBlick:^(UIView *view) {
        [self countSafeClickFunction];
    }];
    
    
    UIImageView *typeImageView=[[UIImageView alloc]initWithFrame:CGRectMake(mainW-22, 45/2-13/2, 7, 13)];
    typeImageView.image=[UIImage imageNamed:@"右箭头"];
    UIView *startDiviView =[[UIView alloc]initWithFrame:CGRectMake(18, 46, mainW-18-15, 1)];
    [startDiviView setBackgroundColor:[UIColor colorWithHexString:@"#eeeeee"]];
    
    [typeView addSubview:typeLabel];
    [typeView addSubview:typeImageView];
    [typeView addSubview:startDiviView];
    
    [self.scrollView addSubview:typeView];
    
    //
    
    //清除缓存
    UIView *clearView  = [[UIView alloc]initWithFrame:CGRectMake(0, 62, mainW, 47)];
    [clearView setBackgroundColor:[UIColor whiteColor]];
    UILabel *clearLabel = [[UILabel alloc]initWithFrame:CGRectMake(15, 0, mainW-24, 45)];
    clearLabel.text=@"清除缓存";
    [clearLabel setTextColor:[UIColor colorWithHexString:@"#2e2e2e"]];
    
    [[SINAUiviewClickLiserner alloc]viewClickFunction:clearView andWithBlick:^(UIView *view) {
        [self clearCountClickFunction];
    }];
    
    UIImageView *clearImageView=[[UIImageView alloc]initWithFrame:CGRectMake(mainW-22, 45/2-13/2, 7, 13)];
    clearImageView.image=[UIImage imageNamed:@"右箭头"];
    UIView *clearDiviView =[[UIView alloc]initWithFrame:CGRectMake(18, 45, mainW-18-15, 1)];
    [clearDiviView setBackgroundColor:[UIColor colorWithHexString:@"#eeeeee"]];
    
    [clearView addSubview:clearLabel];
    [clearView addSubview:clearImageView];
    [clearView addSubview:clearDiviView];
    
    [self.scrollView addSubview:clearView];
    
    
    
    //关于肆迹
    UIView *aboutMeView  = [[UIView alloc]initWithFrame:CGRectMake(0, 108, mainW, 45)];
    [aboutMeView setBackgroundColor:[UIColor whiteColor]];
    UILabel *aboutMeLabel = [[UILabel alloc]initWithFrame:CGRectMake(15, 0, mainW-24, 45)];
    aboutMeLabel.text=@"关于肆迹";
    [aboutMeLabel setTextColor:[UIColor colorWithHexString:@"#2e2e2e"]];
    
    [[SINAUiviewClickLiserner alloc]viewClickFunction:aboutMeView andWithBlick:^(UIView *view) {
        [self aboutMeClickFunction];
    }];
    
    UIView *aboutDiviView =[[UIView alloc]initWithFrame:CGRectMake(18, 44, mainW-18-15, 1)];
    [aboutDiviView setBackgroundColor:[UIColor colorWithHexString:@"#eeeeee"]];
    
    UIImageView *aboutMeImageView=[[UIImageView alloc]initWithFrame:CGRectMake(mainW-22, 45/2-13/2, 7, 13)];
    aboutMeImageView.image=[UIImage imageNamed:@"右箭头"];
    
    [aboutMeView addSubview:aboutMeLabel];
    [aboutMeView addSubview:aboutMeImageView];
    [aboutMeView addSubview:aboutDiviView];
    
    [self.scrollView addSubview:aboutMeView];
    
    
    //帮助与反馈
    UIView *helpFeedbackView  = [[UIView alloc]initWithFrame:CGRectMake(0, 153, mainW, 45)];
    [helpFeedbackView setBackgroundColor:[UIColor whiteColor]];
    UILabel *helpFeedbackLabel = [[UILabel alloc]initWithFrame:CGRectMake(15, 0, mainW-24, 45)];
    helpFeedbackLabel.text=@"帮助与反馈";
    [helpFeedbackLabel setTextColor:[UIColor colorWithHexString:@"#2e2e2e"]];
    
  
    [[SINAUiviewClickLiserner alloc]viewClickFunction:helpFeedbackView andWithBlick:^(UIView *view) {
        if ([super checkApproveIdent]) {
             [self helpFeedbackClickFunction];
        }
    }];
    
    UIImageView *helpFeedbackImageView=[[UIImageView alloc]initWithFrame:CGRectMake(mainW-22, 45/2-13/2, 7, 13)];
    helpFeedbackImageView.image=[UIImage imageNamed:@"右箭头"];
    
    [helpFeedbackView addSubview:helpFeedbackLabel];
    [helpFeedbackView addSubview:helpFeedbackImageView];
    
    [self.scrollView addSubview:helpFeedbackView];
    
    
    // 转换身份
    UIView *selectView  = [[UIView alloc]initWithFrame:CGRectMake(0, 213, mainW, 47)];
    [selectView setBackgroundColor:[UIColor whiteColor]];
    UILabel *selectLabel = [[UILabel alloc]initWithFrame:CGRectMake(15, 0, mainW-24, 45)];
    selectLabel.text=@"转换身份";
    selectView.hidden=YES;
    [selectLabel setTextColor:[UIColor colorWithHexString:@"#2e2e2e"]];
    [selectView addSubview:selectLabel];
   
    
    [[SINAUiviewClickLiserner alloc]viewClickFunction:selectView andWithBlick:^(UIView *view) {
        [self selectIdentClickFunction];
    }];
    
    
    
    [self.scrollView addSubview:selectView];
    
    
    // 退出登录
    UIView *exitLoginView  = [[UIView alloc]initWithFrame:CGRectMake(0, 313-60, mainW, 47)];
    [exitLoginView setBackgroundColor:[UIColor whiteColor]];
    UILabel *exitLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, mainW, 45)];
    exitLabel.text=@"退出登录";
    exitLabel.textColor=[UIColor colorWithHexString:@"#212121"];
    exitLabel.textAlignment=NSTextAlignmentCenter;
    [exitLoginView addSubview:exitLabel];
    
    [[SINAUiviewClickLiserner alloc]viewClickFunction:exitLoginView andWithBlick:^(UIView *view) {
        [self exitLoginClickFunction];
    }];
    
    [exitLoginView setBackgroundColor: [UIColor colorWithHexString:@"ffffff"]];
    
    [self.scrollView addSubview:exitLoginView];
}

//帮助与反馈
-(void)helpFeedbackClickFunction
{

    if ([super checkApproveIdent]) {
        SINAHelpFeedbackViewController * helpFeedbackViewController = [[SINAHelpFeedbackViewController alloc]init];
        helpFeedbackViewController.helpFeedbackType = SINAHELPFEEDBACK_STUDENT_TYPE;
        [self.navigationController pushViewController:helpFeedbackViewController animated:YES];
    }
}

-(void)configNavigationItem{
    self.navigationController.navigationBarHidden = NO;
    self.navigationItem.title=@"设置";
    self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:0/255 green:198.0/255 blue:174.0/255 alpha:0.8f];
    self.navigationController.navigationBar.translucent = NO;
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:18],
                                                                      NSForegroundColorAttributeName:[UIColor whiteColor]}];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


//账号安全
-(void)countSafeClickFunction{
    SINAStudentCountSafeViewController *controll=[[SINAStudentCountSafeViewController alloc]init];
    [self.navigationController pushViewController:controll animated:YES];
}

//清除缓存
-(void)clearCountClickFunction{
    NSString *message =@"已清除缓存 10 M";
    WISAlertView *alertView =   [[WISAlertView alloc]initWithTitle:@"提示" message:message sureBtn:@"确定"
                                                         cancleBtn:nil];
    [alertView showXLAlertView];
}
//
-(void)aboutMeClickFunction{
    SINAAboutMeViewController *aboutMeController = [[SINAAboutMeViewController alloc]initWithNibName:@"SINAAboutMeViewController" bundle:nil];
    [self.navigationController pushViewController:aboutMeController animated:YES];
}
//选择身份
-(void)selectIdentClickFunction{
    SINAStudentSelectIdentViewController
    *aboutMeController = [[SINAStudentSelectIdentViewController alloc]initWithNibName:@"SINAStudentSelectIdentViewController" bundle:nil];
    [self.navigationController pushViewController:aboutMeController animated:YES];
    
}
-(void)viewWillAppear:(BOOL)animated{
    self.navigationController.navigationBarHidden = NO;
}
//退出登录
-(void)exitLoginClickFunction{
    
    WISAlertView *alertView =   [[WISAlertView alloc]initWithTitle:@"提示" message:@"确定退出登录?" sureBtn:@"确定"
                                                         cancleBtn:@"取消"];
//    __weak typeof(self) weakSelf = self;
    alertView.resultIndex = ^(NSInteger index) {
        
//        [JPUSHService deleteAlias:^(NSInteger iResCode, NSString *iAlias, NSInteger seq) {
//            DLog(@"别名注QI册完成 seq %ld and iResCode %ld",(long)iResCode,seq);
//        } seq:101];
        [JPUSHService setAlias:@"123" completion:^(NSInteger iResCode, NSString *iAlias, NSInteger seq) {
            DLog(@"别名注册完成 seq %ld and iResCode %ld",(long)iResCode,seq);
        } seq:102];
        //清除数据 
        [[SINACommonUserHelper share] clearUserModel];
        //登录页面
        SINALoginViewController *rootViewControll = [[SINALoginViewController alloc]init ];
        SINANavLoginViewController *homeController = [[SINANavLoginViewController alloc] initWithRootViewController:rootViewControll];
        [[SINAControllerUtils  alloc]restoreRootViewController:homeController andWithWindow:self.view.window];
    };
    [alertView showXLAlertView];
    
    
}
/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
